import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:raze/potions/raze_constant.dart';
import 'package:raze/potions/spatial_alchemy.dart';

/// 举报弹窗组件
/// 用户点击举报按钮时显示，包含多个举报选项
class ReportVaultDialog {
  /// 显示举报弹窗
  /// [onReportSubmitted] 提交举报的回调函数，参数为选中的举报类型
  static void revealReportVault({required Function(String) onReportSubmitted}) {
    Get.dialog(
      _ReportVaultWidget(onReportSubmitted: onReportSubmitted),
      barrierDismissible: true,
    );
  }
}

/// 举报弹窗内部组件
class _ReportVaultWidget extends StatefulWidget {
  final Function(String) onReportSubmitted;

  const _ReportVaultWidget({required this.onReportSubmitted});

  @override
  State<_ReportVaultWidget> createState() => _ReportVaultWidgetState();
}

class _ReportVaultWidgetState extends State<_ReportVaultWidget> {
  String? _selectedReason;
  final List<String> _reportReasons = [
    'Inappropriate Content',
    'Harassment/Bullying',
    'Spam/Advertisement',
    'Other Issues',
    'Block User',
  ];

  /// 提交举报
  void _submitReport() {
    if (_selectedReason == null) {
      return;
    }
    widget.onReportSubmitted(_selectedReason!);
    Get.back();
  }

  @override
  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: Colors.transparent,
      elevation: 0,
      child: Container(
        width: 340.w,
        decoration: BoxDecoration(
          color: RazeConstants.white,
          borderRadius: BorderRadius.circular(20.r),
          border: Border.all(
            color: RazeConstants.blue.withOpacity(0.3),
            width: 2,
          ),
          boxShadow: [
            BoxShadow(
              color: RazeConstants.black.withOpacity(0.15),
              blurRadius: 20,
              offset: const Offset(0, 8),
            ),
          ],
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            16.h.boxHeight,

            // 标题
            Text('Report Content')
                .applyTypeSize(20.sp)
                .applyTypeColor(RazeConstants.black)
                .applyNotoSans(weight: FontWeight.bold),
            6.h.boxHeight,
            Text('Please select a reason')
                .applyTypeSize(13.sp)
                .applyTypeColor(RazeConstants.black.withOpacity(0.6))
                .applyNotoSans()
                .enshroudHorizontal(24.w),
            16.h.boxHeight,

            // 举报选项列表
            Column(
              children:
                  _reportReasons.map((reason) {
                    final isSelected = _selectedReason == reason;
                    return Container(
                      margin: EdgeInsets.only(bottom: 8.h),
                      decoration: BoxDecoration(
                        color:
                            isSelected
                                ? RazeConstants.blue.withOpacity(0.1)
                                : RazeConstants.background,
                        borderRadius: BorderRadius.circular(12.r),
                        border: Border.all(
                          color:
                              isSelected
                                  ? RazeConstants.blue
                                  : Colors.transparent,
                          width: isSelected ? 2.w : 2.w,
                        ),
                      ),
                      child: InkWell(
                        onTap: () {
                          setState(() {
                            _selectedReason = reason;
                          });
                        },
                        borderRadius: BorderRadius.circular(12.r),
                        child: Row(
                          children: [
                            // 单选按钮
                            Container(
                              width: 18.w,
                              height: 18.w,
                              margin: EdgeInsets.only(left: 16.w, right: 12.w),
                              decoration: BoxDecoration(
                                shape: BoxShape.circle,
                                border: Border.all(
                                  color:
                                      isSelected
                                          ? RazeConstants.blue
                                          : RazeConstants.black.withOpacity(
                                            0.3,
                                          ),
                                  width: 2,
                                ),
                                color:
                                    isSelected
                                        ? RazeConstants.blue
                                        : Colors.transparent,
                              ),
                              child:
                                  isSelected
                                      ? Icon(
                                        Icons.check,
                                        size: 12.sp,
                                        color: RazeConstants.white,
                                      )
                                      : null,
                            ),
                            // 选项文本
                            Expanded(
                              child: Text(reason)
                                  .applyTypeSize(13.sp)
                                  .applyTypeColor(
                                    isSelected
                                        ? RazeConstants.blue
                                        : RazeConstants.black,
                                  )
                                  .applyNotoSans(
                                    weight:
                                        isSelected
                                            ? FontWeight.w600
                                            : FontWeight.normal,
                                  )
                                  .enshroudVertical(12.h)
                                  .enshroudRight(16.w),
                            ),
                          ],
                        ),
                      ),
                    ).enshroudHorizontal(24.w);
                  }).toList(),
            ),

            16.h.boxHeight,

            // 装饰分隔线
            Container(
              width: 280.w,
              height: 1,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: [
                    Colors.transparent,
                    RazeConstants.blue.withOpacity(0.3),
                    Colors.transparent,
                  ],
                ),
              ),
            ),
            16.h.boxHeight,

            // 按钮区域
            Row(
              children: [
                // 取消按钮
                Expanded(
                  child: Container(
                        height: 48.h,
                        decoration: BoxDecoration(
                          border: Border.all(
                            color: RazeConstants.black.withOpacity(0.2),
                            width: 1.5,
                          ),
                          borderRadius: BorderRadius.circular(12.r),
                        ),
                        child: Center(
                          child: Text('Cancel')
                              .applyTypeSize(16.sp)
                              .applyTypeColor(
                                RazeConstants.black.withOpacity(0.6),
                              )
                              .applyNotoSans(weight: FontWeight.bold),
                        ),
                      )
                      .enshroudLeft(24.w)
                      .enshroudRight(8.w)
                      .withTouchResonance(
                        onTap: () {
                          Get.back();
                        },
                      ),
                ),

                // 提交按钮
                Expanded(
                  child: Container(
                        height: 48.h,
                        decoration: BoxDecoration(
                          color:
                              _selectedReason != null
                                  ? RazeConstants.red
                                  : RazeConstants.black.withOpacity(0.2),
                          borderRadius: BorderRadius.circular(12.r),
                          boxShadow:
                              _selectedReason != null
                                  ? [
                                    BoxShadow(
                                      color: RazeConstants.red.withOpacity(0.3),
                                      blurRadius: 8,
                                      offset: const Offset(0, 4),
                                    ),
                                  ]
                                  : null,
                        ),
                        child: Center(
                          child: Text('Submit')
                              .applyTypeSize(16.sp)
                              .applyTypeColor(
                                _selectedReason != null
                                    ? RazeConstants.white
                                    : RazeConstants.black.withOpacity(0.4),
                              )
                              .applyNotoSans(weight: FontWeight.bold),
                        ),
                      )
                      .enshroudLeft(8.w)
                      .enshroudRight(24.w)
                      .withTouchResonance(
                        onTap: _selectedReason != null ? _submitReport : null,
                      ),
                ),
              ],
            ),

            24.h.boxHeight,
          ],
        ),
      ),
    );
  }
}
